package leetcode;

public class _1759 {
    /**
     * 统计同质子字符串的数目
     */
    class Solution {
        public int countHomogenous(String s) {
            int n  = s.length();
            char[] cs = s.toCharArray();
            long sum=0;
            int cnt = 0;
            char pre = cs[0];
            for(int i=0;i<n;i++){
                char c = cs[i];
                if(c==pre){
                    pre=c;
                    cnt++;
                }else{
                    sum+=(cnt+1)*cnt/2;
                    pre=c;
                    cnt=1;
                }
            }
            sum = sum+(long)(cnt+1)*cnt/2;
            return (int)(sum%1000000007);
        }
    }
}
